package com.cloudbroker.bcs.platform.ltb.common.util.zookeeper;

import com.cloudbroker.bcs.common.configure.HSBCSZooKeeperConfigurator;
import com.cloudbroker.bcs.common.context.RuntimeContext;
import com.cloudbroker.bcs.common.datasource.druid.TenantIdMappingDataSource;
import com.cloudbroker.bcs.common.event.annotation.On;
import com.cloudbroker.bcs.platform.ltb.common.util.CacheHelper;

/**
 * Created by lili19289 on 2016/11/1.
 */
public class ZookeeperConfigureRefresh {


    @On(eventName = "db" + HSBCSZooKeeperConfigurator.EVT_RELOAD_SUFFIX)
    public  void refreshDataSource(String sourceName) throws Exception{
        TenantIdMappingDataSource dataSource = RuntimeContext.getBean(TenantIdMappingDataSource.class);
        if(dataSource!=null) {
            dataSource.refreshDataSource(null);
        }
    }

    @On(eventName = "cache" + HSBCSZooKeeperConfigurator.EVT_RELOAD_SUFFIX)
    public  void refreshCache(){
        CacheHelper cacheHelper = CacheHelper.getInstance();
        cacheHelper.refreshCache();
    }


//    @On(eventName = "searchEngine" + HSBCSZooKeeperConfigurator.EVT_RELOAD_SUFFIX)
//    public  void refreshElasticsearch(){
//        Client client=null;
//        try {
//            ElasticsearchBase elasticsearch=RuntimeContext.getBean(ElasticsearchBase.class);
//            if(elasticsearch!=null) {
//                client = elasticsearch.getClient();
//                elasticsearch.destory();
//            }
//        } catch (UnknownHostException e) {
//            e.printStackTrace();
//        }
//
//    }
}
